// Copyright (C) ZHENG Zhong <heavyzheng nospam-at gmail D0T com>
//
// $Id: logger.hpp 216 2008-09-03 08:13:29Z heavyzheng $
//

#ifndef ZZHENG_LOGGING_NONE_LOGGER_HPP_20080902__
#define ZZHENG_LOGGING_NONE_LOGGER_HPP_20080902__

#include <zzheng/logging/none/config.hpp>
#include <zzheng/logging/log_level.hpp>

#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <string>
#include <map>

namespace zzheng {
namespace logging {
namespace none_ {

    class ZZHENG_LOGGING_DECL log_factory; // forward declaration.

    //! The logger implementation class based on log4cplus::Logger.
    class ZZHENG_LOGGING_DECL logger: private boost::noncopyable {

        typedef std::map<std::string, boost::shared_ptr<logger> > child_map;

        friend log_factory;

    public:

        // Use auto-generated destructor.

        //! Returns the name of this logger.
        //! \return the name of this logger.
        std::string name() const;

        //! Returns the threshold of this logger.
        //! \return the threshold of this logger.
        log_level threshold() const;

        //! Sets the threshold to this logger.
        //! \param threshold  the new threshold to set.
        void set_threshold(const log_level& threshold);

        //! Returns a child logger object by name. If the requested child logger does not exist,
        //! this function will create a new one.
        boost::weak_ptr<logger> child(const std::string& child_name);

        //! Logs a message to this logger at the specified log level.
        //! \param level  the log level of the message.
        //! \param msg    the message to log.
        void log(const log_level& level, const std::string& msg);

    private:

        //! Constructs a logger.
        //! \param name       the name of the logger.
        //! \param threshold  the threshold of the logger.
        explicit logger(const std::string& name, const log_level& threshold);

    private:

        std::string name_;      //!< The logger name.
        log_level   threshold_; //!< The threshold of this logger.
        child_map   children_;  //!< The child logger objects.

    }; // class logger


} // namespace zzheng::logging::none_
} // namespace zzheng::logging
} // namespace zzheng

#endif // ZZHENG_LOGGING_NONE_LOGGER_HPP_20080902__


